<?php

class Exam_Form_Search extends Engine_Form
{
//    protected $parent_id = 0;
//    public function setCountry($id){
//        $this->parent_id = $id;
//    }
//    
      public function init()
      {
        $this
          ->setAttribs(array(
            'id' => 'filter_form',
            'class' => 'global_form_box',
          ))
          ->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()));
        
        $this->addElement('Text', 'search', array(
          'label' => 'Search Exams',
          'onchange' => 'this.form.submit();',
        ));
    
        $this->addElement('Select', 'orderby', array(
          'label' => 'Browse By',
          'multiOptions' => array(
            'creation_date' => 'Most Recent',
            'view_count' => 'Most Viewed',
          ),
          'onchange' => 'this.form.submit();',
        ));
    
        $this->addElement('Select', 'show', array(
          'label' => 'Show',
          'multiOptions' => array(
            '1' => 'Everyone\'s Exams',
            '2' => 'Only My Friends\' Exams',
          ),
          'onchange' => 'this.form.submit();',
        ));
    
        // get Parent Categories
        $Pcategories = Exam_Model_DbTable_Categories::getParentCategory();
        $i=0;
        foreach ($Pcategories as $category) {
            $categoy_prepared[$category->category_id] = $category->category_name;
            if ($i==0){
                $parent_id_index_0 = $category->category_id;
            }
            $i = $i+1 ;
        }        
        //Parent categories
        $this->addElement('Select', 'category', array(
          'label' => 'Category',
          'multiOptions' => $categoy_prepared,
          'onchange' => 'loadCategory(this.value)',
        ));
        $this->category->setValue($parent_id_index_0);
            
        //get sub categories
        $city_prepared = array();
        $Scategories = Exam_Model_DbTable_Categories::getSubCategory($parent_id_index_0);
                
        foreach ($Scategories as $category) {
            $Scategories_prepared[$category->category_id] = $category->category_name;
        }
    	//Sub categories
        $this->addElement('Select', 'category2', array(
        		'label' => 'Category 2',
        		'multiOptions' => $Scategories_prepared,
        	'onchange' => 'this.form.submit();',
        ));
        
        $this->addElement('Hidden', 'page', array(
          'order' => 100
        ));
    
        $this->addElement('Hidden', 'tag', array(
          'order' => 101
        ));
    
        $this->addElement('Hidden', 'start_date', array(
          'order' => 102
        ));
    
        $this->addElement('Hidden', 'end_date', array(
          'order' => 103
        ));
      }
}